package cn.iocoder.yudao.module.measure.dal.dataobject.protocol;

import com.baomidou.mybatisplus.annotation.*;
import lombok.*;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.LinkedList;

import static com.baomidou.mybatisplus.annotation.SqlCondition.EQUAL;
import static com.baomidou.mybatisplus.annotation.SqlCondition.LIKE;

/**
 * <p>
 * 实体类
 * 数据上传协议配置-主表
 * </p>
 *
 * @author zhengbzh
 * @date 2025-05-22 13:51:07
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString(callSuper = true)
@Accessors(chain = true)
@Builder
@TableName("template_device_upload_protocol")
public class TemplateDeviceUploadProtocol implements Serializable {
    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.INPUT)
    protected Long id;

    @TableField(value = "created_time", fill = FieldFill.INSERT)
    protected LocalDateTime createdTime;

    @TableField(value = "created_by", fill = FieldFill.INSERT)
    protected Long createdBy;

    @TableField(value = "updated_time", fill = FieldFill.INSERT_UPDATE)
    protected LocalDateTime updatedTime;

    @TableField(value = "updated_by", fill = FieldFill.INSERT_UPDATE)
    protected Long updatedBy;

    @TableField(exist = false)
    private LinkedList<TemplateDeviceUploadMessage> messageTemplateList;

    /**
     * 协议名称
     */
    @TableField(value = "protocol_name", condition = LIKE)
    private String protocolName;
    /**
     * 连接方式
     */
    @TableField(value = "connect_type", condition = EQUAL)
    private String connectType;
    /**
     * mqtt连接时订阅的topic
     */
    @TableField(value = "mqtt_topic", condition = LIKE)
    private String mqttTopic;

    /**
     * 测量点id 只有在关联设备表时候才有值
     */
    @TableField(exist = false)
    private String measurePointId;

    /**
     * 租户id 只有手动赋值后才有值
     */
    @TableField(exist = false)
    private Long tenantId;


    public TemplateDeviceUploadMessage getCommand(String commandStr) {
        for(TemplateDeviceUploadMessage messageTemplate:messageTemplateList){
            if(messageTemplate.getMessageCode().equals(commandStr)){
                return messageTemplate;
            }
        }
        return null;
    }
}
